/*
 * Killocan 2013
 * http://killocan.blogspot.com
*/

#include <allegro.h>

#include "text_utils.h"
    
void draw_text(FONT * mm_font, int x, int y, int fg, int bg, const char * str)
{
	static const int charLen = text_length(mm_font, "A");
	for (unsigned int i = 0; i < strlen(str); i++)
	{
	  textprintf_ex(screen, mm_font, x, y, fg, bg, "%c", str[i]);
	  x+=charLen;
	  rest(100);
	}
}

void draw_text_shadow(BITMAP * buffer, FONT * mm_font, int x, int y, int fg, const char * str)
{
  if (fg == 0) return;

  textprintf_ex(buffer, mm_font, x+2, y+2, 0,  -1, "%s", str);
  textprintf_ex(buffer, mm_font, x,   y,   fg, -1, "%s", str);
}

void draw_number(FONT * mm_font, int x, int y, int fg, int bg, int number)
{
  int rndNumber = (rand()%10);
  static const int oht = 100*1000;

  if (number >= oht)
  {
  	rndNumber = (rndNumber*oht) + (number%oht);
  	textprintf_ex(screen, mm_font, x+2, y+2, 0,  bg, "%d  ", rndNumber);
    textprintf_ex(screen, mm_font, x,   y,   fg, -1, "%d  ", rndNumber);
  }
  else
  {
    textprintf_ex(screen, mm_font, x+2, y+2, 0,  bg, "%d", number);
    textprintf_ex(screen, mm_font, x,   y,   fg, -1, "%d", number);

    textprintf_ex(screen, mm_font, x+2, y+2, 0,  bg, "%d", rndNumber);
    textprintf_ex(screen, mm_font, x,   y,   fg, -1, "%d", rndNumber);
  }
}
